package main

func main() {

	a := generate(5)
	for _, v := range a {

		for _, w := range v {
			print(w)
		}

		println()

	}

}

// 杨辉三角
func generate(numRows int) [][]int {

	if numRows == 0 {
		return [][]int{{}}
	}

	if numRows == 1 {
		return [][]int{{1}}
	}

	result := [][]int{{1}, {1, 1}}
	preRow := []int{1, 1}

	for i := 2; i < numRows; i++ {

		// f(i) = f(f(i-1))
		nowRow := []int{}

		nowRow = append(nowRow, 1)
		for j := 1; j < i; j++ {
			v := preRow[j-1] + preRow[j]
			nowRow = append(nowRow, v)
		}
		nowRow = append(nowRow, 1)

		result = append(result, nowRow)
		preRow = nowRow
	}
	return result
}
